<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title>让坦克开起来</title>
	<style type="text/css">
		input {
			font-size: 26px;
			margin-top: 20px;
		}

		body {
			background-image: url(images/grassland.png);
		}

		#mytank {
			position: absolute;
			left: 10px;
			top: 100px
		}
	</style>
</head>

<body>
	<img id="mytank" src="images/right.png" />
	<script>
		// 199000838司泽华
		var mytank = document.querySelector('img');
		var bgHig = window.screen.height;
		var bgWid = window.screen.width;
		document.onkeydown = function (e) {
			if (e.keyCode == "87") {
				mytank.src = "images/up.png";
				if (mytank.offsetTop >= 0)
					mytank.style.top = mytank.offsetTop - 9 + "px";
			}
			else if (e.keyCode == "65") {
				mytank.src = "images/left.png"
				if (mytank.offsetLeft >= 0)
					mytank.style.left = mytank.offsetLeft - 9 + "px";
			}
			else if (e.keyCode == "83") {
				mytank.src = "images/down.png"
				if (mytank.offsetTop <= bgHig)
					mytank.style.top = mytank.offsetTop + 9 + "px";
			}
			else if (e.keyCode == "68") {
				mytank.src = "images/right.png"
				if (mytank.offsetLeft <= bgWid)
					mytank.style.left = mytank.offsetLeft + 9 + "px";
			}
		}
		window.oncontextmenu=function(e){
			e.preventDefalut();
		}
		document.onmousedown=function(){
				if(event.button==2){
					alert("当前界面禁用右键！");
					return false;
				}
			}

	</script>
</body>

</html>